package experiment4;

public class Account {
    private String userName;
    private int id;
    private int certain;

    public Account() {
    }

    public Account(String userName, int id, int certain) {
        this.userName = userName;
        this.id = id;
        this.certain = certain;
    }

    public String getUserName() {
        return userName;
    }

    public void setUserName(String userName) {
        this.userName = userName;
    }

    public int getId() {
        return id;
    }

    public void setId(int id) {
        this.id = id;
    }

    public int getCertain() {
        return certain;
    }

    public void setCertain(int certain) {
        this.certain = certain;
    }

    //存款
    public void addMoney(int money){
        int newMoney=money+getCertain();
        setCertain(newMoney);
    }

    //取款
    public int getMoney(int money){
        if(money<=this.certain&&money>=this.certain){
            int newMoney=getCertain()-money;
            setCertain(newMoney);
            return money;
        }else {
            System.out.println("余额不足");
            return 0;
        }

    }

    //显示余额
    public void showCertain(){
        System.out.println(getCertain());
    }

    //申请银行账户
    public void applyBankAccount(Bank bank,Account p){
        for (int i = 0; i < bank.getBank().length; i++) {
            if(bank.getBank()[i]==p){
                System.out.println("已存在该账户");
                return;
            }
            if(bank.getBank()[i]==null){
                bank.getBank()[i]=p;
                System.out.println("添加成功");
                return;
            }
        }
        System.out.println("该银行账户已满");
    }
}
